package com.gator.desig_mode.factoryMethod.factory;


import com.gator.desig_mode.factoryMethod.car.Car;

/**
 * @author 何章怀晓 hezhanghuaixiao
 * @version V1.0
 * @desc 根据参数返回工厂对应方法
 */
public class Business {

  public Business(int flag, String para,
      CarFactoryBase carFactoryBase) {
    this.flag = flag;
    this.para = para;
    this.carFactoryBase = carFactoryBase;
  }

  //实际开发中，flag和para是上游传来的参数
  private int flag;

  public int getFlag() {
    return flag;
  }

  public void setCarFactoryBase(CarFactoryBase carFactoryBase) {
    this.carFactoryBase = carFactoryBase;
  }

  public String getPara() {
    return para;
  }

  public CarFactoryBase getCarFactoryBase() {
    return carFactoryBase;
  }

  private String para;

  @Override
  public String toString() {
    return "Business{" +
        "flag=" + flag +
        ", para='" + para + '\'' +
        ", carFactoryBase=" + carFactoryBase +
        '}';
  }

  private CarFactoryBase carFactoryBase;

  public void setFlag(int flag) {
    this.flag = flag;
  }

  public void setPara(String para) {
    this.para = para;
  }

  public void setCarFactory(CarFactoryBase carFactoryBase) {
    this.carFactoryBase = carFactoryBase;

    Car car = null;
    //中国
    if (flag == 0) {
      car = new ChinaCarFactory().create(para);
    }
    //国外
    if (flag == 1) {
      car = new ImportedCarFactory().create(para);
    }

    car.start();
  }


}
